import server from '@/utils/fetch'

// 登录注册
export const login = (data) => {
    const { username, password, identity = 0 } = data;
    const encode = btoa(encodeURI(username + ':' + password))
    return server.get('/v1/token', {
        headers: {
            authorization: 'Basic ' + encode,
            'x-identity': identity
        }
    })
}

export const register = (data) => {
    return server.post('/v1/registry', { ...data })
}

// 患者修改信息
export const updateUser = (data) => {
    console.log(typeof data)
    return server.put('/v1/user/' + localStorage.getItem('patient_id'), { ...data })
}

// 医生修改信息
export const updateDUser = (data) => {
    return server.put('/v1/user/' + localStorage.getItem('doctor_id'), { ...data })
}

// 查看用户名是否重复
export const repeatUserName = (username) => {
    return server.get(`/v1/registry/${username}`)
}
